package com.zgm.ch06.aop.aspectJ.advice.before._2_5_1;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import com.zgm.ch06.aop.common.SecurityContext;

@Aspect
public class BeforeAspect {

	@Pointcut("execution(* com.zgm.ch06.aop.services.*.*(..))")
	private void serviceExcution() {}
	
	@Pointcut("execution(* com.zgm.ch06.aop.services.UserService.login(..))")
	private void loginExcution() {}
	
	@Before("serviceExcution() && !loginExcution()")
	public void beforeLogin() throws Throwable {
		if(SecurityContext.getCurrentUser() == null) {
			throw new RuntimeException("必须先登录后才能访问这个方法");
		}
	}
	
	/*@Before("execution(* com.zgm.ch06.aop.services.*.*(..))")
	public void beforeLogin() throws Throwable {
		if(SecurityContext.getCurrentUser() == null) {
			throw new RuntimeException("必须先登录后才能访问这个方法");
		}
	}*/
}
